package com.dyz.leetcode._10_slidingWindow;

public class _209_minSubArrayLen {
    public int minSubArrayLen(int target, int[] nums) {
        int ans = Integer.MAX_VALUE;
        int left=0;
        int right = 0;
        int windowSum = 0;
        while (right<nums.length){
            windowSum += nums[right];
            while(windowSum>=target){
                ans = Math.min(ans, right-left+1);
                windowSum -= nums[left];
                left++;
            }
            right++;
        }
        return ans==Integer.MAX_VALUE?0:ans;
    }
}
